﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Text;
using System.Windows.Forms;
using foursquare.Foursquare;

namespace foursquare.Forms
{
    public partial class TipPanel : UserControl
    {
        public TipPanel(Tip t)
        {
            InitializeComponent();
            Create(t);

        }

        public void Create(Tip t)
        {
            Rectangle rect = this.ClientRectangle;

            LinkLabel lblTip = new LinkLabel();
            lblTip.Text = t.text;
            lblTip.Width = rect.Width;
            int rowHeight = (int)CFMeasureString.MeasureString(lblTip, lblTip.Text, rect).Height;

            lblTip.Height = rowHeight;
            lblTip.Tag = t.venue.id;
            lblTip.Click += new EventHandler(lblTip_Click);
            lblTip.Dock = DockStyle.Bottom;
            this.Controls.Add(lblTip);

            LinkLabel lblCreated = new LinkLabel();
            lblCreated.Text = t.created.ToLocalTime().ToString();
            lblCreated.TextAlign = ContentAlignment.TopRight;
            lblCreated.Width = rect.Width;
            lblCreated.Height = rowHeight;
            if (t.user != null)
            {
                lblCreated.Tag = t.user.id;
                lblCreated.Click += new EventHandler(lblUser_Click);
            }
            lblCreated.Dock = DockStyle.Bottom; 
            this.Controls.Add(lblCreated);

            this.Height = rowHeight * this.Controls.Count + 2;
        }

        private void lblTip_Click(object sender, EventArgs e)
        {
            LinkLabel lbl = (LinkLabel)sender;
            VenueView view = new VenueView(lbl.Tag.ToString());
            view.Show();
        }

        private void lblUser_Click(object sender, EventArgs e)
        {
            LinkLabel lbl = (LinkLabel)sender;
            UserView view = new UserView(lbl.Tag.ToString());
            view.Show();
        }

    }
}
